package swing;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.border.EmptyBorder;

import Server.start;

import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JList;
import javax.swing.JTextArea;

public class testswing extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try
	    {
	        org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper.launchBeautyEyeLNF();
	    }
	    catch(Exception e)
	    {
	        System.out.println(e);
	    }
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					testswing frame = new testswing();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public testswing() {
		String[] model = {"FIHC","K-means"};
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 491, 385);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		textField = new JTextField();
		textField.setBounds(10, 13, 86, 24);
		contentPane.add(textField);
		textField.setColumns(10);
		
		textField_1 = new JTextField();
		textField_1.setBounds(128, 13, 86, 24);
		contentPane.add(textField_1);
		textField_1.setColumns(10);
		
		JComboBox comboBox = new JComboBox(model);
		comboBox.setBounds(265, 13, 113, 24);
		contentPane.add(comboBox);
		
		JTextArea textArea = new JTextArea();
		JScrollPane scroll = new JScrollPane(textArea);
		scroll.setBounds(229, 120, 230, 207);
		scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
		scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
		contentPane.add(scroll);
		
		JButton button = new JButton("开始搜索");
		button.setBounds(14, 99, 113, 27);
		contentPane.add(button);
		button.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				String begin = textField.getText();
				String end = textField_1.getText();
				start start = new start();
				if(comboBox.getSelectedItem().equals("FIHC")){
				List<String> liStrings = start.getFIHCresult(begin, end);
				String result = liStrings.get(0);
				liStrings.remove(0);
				for(String s:liStrings){
					result+=("\n"+s);
				}
				textArea.setText(result);
			}
				else {
					List<String> liStrings = start.getKMresult(begin, end);
					String result = liStrings.get(0);
					liStrings.remove(0);
					for(String s:liStrings){
						result+=("\n"+s);
					}
					textArea.setText(result);
				}
			}
		});
		
		
		
	}
}
